package com.zjw.zy.coreui.fragment.weather

import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.zjw.zy.R
import com.zjw.zy.base.BaseFragment
import com.zjw.zy.base.BaseRecyclerAdapter
import com.zjw.zy.coreui.fragment.adapter.Weather15Adapter
import com.zjw.zy.coreui.fragment.holder.Weather15Holder
import com.zjw.zy.coreui.dialog.WeatherDialog
import com.zjw.zy.ext.mainActivity
import com.zjw.zy.utils.ResourcesUtils
import com.zjw.zy.utils.WindowUtils
import com.zjw.zy.viewmodel.WeatherViewModel

/**
 * @author     ：zhong.jw
 * @date       ：Created in 2022/9/28 11:47
 * @description：15日天气Fragment
 */
class Weather15Fragment : BaseFragment() {

    private val mWeatherViewModel: WeatherViewModel by activityViewModels()

    private val mList: RecyclerView by lazy { findViewById(R.id.weather_fragment_list) }

    private val mAdapter: Weather15Adapter =
        Weather15Adapter(object : BaseRecyclerAdapter.ItemListener<Weather15Holder> {
            override fun onItemClick(holder: Weather15Holder, v: View) {
                WeatherDialog.showWeather(holder.data)
            }

            override fun onItemLongClick(holder: Weather15Holder, v: View): Boolean {
                return false
            }

            override fun onItemDoubleClick(holder: Weather15Holder, v: View) {
            }

        })

    override fun onPageEnter() {
        WindowUtils.TopBar.showBack()
        WindowUtils.TopBar.setTopBarLabelText(ResourcesUtils.getString(R.string.weather_15_weather))
        WindowUtils.TopBar.hideAllRightButton()
        WindowUtils.FootBar.hide()
    }

    override fun onViewRestore(savedInstanceState: Bundle?) {

    }

    override fun onSubscribe() {
        mWeatherViewModel.get15Weather().observe(this) {
            it?.let {
                mAdapter.notifyData(it.dailyFcsts)
            }
        }
    }

    override fun onPageCreate() {
        super.onPageCreate()
        mWeatherViewModel.request15DayWeather()
    }

    override fun onBindViewListener() {

    }

    override fun onBindViewValue() {
        mList.adapter = mAdapter
        mList.layoutManager = LinearLayoutManager(mainActivity())
    }

    override fun onFindView(rootView: View?) {

    }

    override fun onLayoutId(): Int {
        return R.layout.main_weather_15_day_fragment
    }

    override fun onPageExit() {

    }
}